import axios from 'axios'
import { Message } from 'ant-design-vue'

const service = axios.create({
  baseURL: 'http://rap2api.taobao.org/app/mock/283047',
  withCredentials: true,
  timeout: 40000
})

// request interceptor
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    console.log(error) // for debug
    return Promise.reject(error)
  }
)

// response interceptor
service.interceptors.response.use(
  response => {
    const res = response.data
    return res
  },
  error => {
    console.log('err' + error) // for debug
    Message.error(
      error.message,
      5
    )
    return Promise.reject(error)
  }
)

export default service
